﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace PSE.Deployment.SetupBase.Configuration.Actions
{
    [Serializable]
    public class RegisterComponentWin32 : ActionBase
    {
        public List<FolderInfo> Folders { get; set; }

        /// <summary>
        /// Verificar se existe uma referencia para um arquivo em algumas das folders
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public override bool HasFile(string filePath)
        {
            if (string.IsNullOrEmpty(filePath) || this.Folders == null || this.Folders.Count == 0)
                return false;
            else
            {
                //TODO:CODIGO MARRETADO - Quando for alterado para o filePath conter o id do sistema, remover a utilizacao do metodo RemoveRootLevel
                foreach (FolderInfo folder in this.Folders)
                {
                    if (folder.Files != null && folder.Files.Count > 0)
                    {
                        foreach (string file in folder.Files)
                        {
                            if (PSE.Deployment.Util.File.RemoveRootLevel(file).Equals(filePath, StringComparison.CurrentCultureIgnoreCase))
                                return true;
                        }
                    }
                    else
                    {
                        if (filePath.StartsWith(PSE.Deployment.Util.File.RemoveRootLevel(folder.Destination), StringComparison.CurrentCultureIgnoreCase))
                            return true;
                    }
                }

                return false;
            }
        }
    }
}
